package com.gin.kotlin.no_gay_alliance.fragment.post

import android.os.Bundle
import com.gin.kotlin.no_gay_alliance.adapter.emoji.GenericEmojiGroupPreviewAdapter
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingFragment
import com.gin.kotlin.no_gay_alliance.base.SimpleItemDecoration
import com.gin.kotlin.no_gay_alliance.databinding.FragmentPostEmojiTabBinding
import com.gin.kotlin.no_gay_alliance.model.emoji.GenericEmojiGroup

class PostEmojiTabFragment : AbstractBindingFragment<FragmentPostEmojiTabBinding>() {
    private lateinit var group: GenericEmojiGroup

    /**
     * onCreateView的后续操作 ，如通过  [FragmentActivity.addMenuProvider] 添加菜单
     */
    override fun onCreateView() {
        val b = this.b ?: return

        group.data?.toMutableList()?.also {
            b.recyclerView.adapter = GenericEmojiGroupPreviewAdapter(requireContext(), handler!!, it)
            b.recyclerView.addItemDecoration(SimpleItemDecoration())
        }
    }

    /**
     * 处理参数
     * @param bundle Bundle
     */
    override fun handleArguments(bundle: Bundle) {
        super.handleArguments(bundle)
        this.group = parseBundle(bundle, KEY_ARGUMENT, GenericEmojiGroup::class.java)
    }

    companion object {
        private const val KEY_ARGUMENT = "GROUP"
        fun newInstance(data: GenericEmojiGroup) = PostEmojiTabFragment().also {
            val args = Bundle()
            args.putParcelable(KEY_ARGUMENT, data)
            it.arguments = args
        }
    }
}